// 连接mongodb
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/demo', {
  useNewUrlParser: true,
  useUnifiedTopology: true
});
const db = mongoose.connection;
db.on('error', console.error.bind(console, '数据库连接失败'));
db.once('open', function() {
  // 数据库打开了 连接成功
  console.log('mongodb连接成功');
});